package cc.langk.web.mapper;

import cc.langk.web.entity.SysRole;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.type.JdbcType;

public interface SysRoleMapper {
    @Delete({
        "delete from sys_role",
        "where ROW_ID = #{rowId,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long rowId);

    @Insert({
        "insert into sys_role (PARENT_ROLE_ID, PARENT_ROLE_NAME, ",
        "ROLE_TYPE, ROLE_NAME, ",
        "ROLE_REMARK, DEL_FLAG, ",
        "CREATE_TIME, CREATE_ID, ",
        "CREATE_ACCOUNT, OPT_TIME, ",
        "OPT_ID, OPT_ACCOUNT)",
        "values (#{parentRoleId,jdbcType=BIGINT}, #{parentRoleName,jdbcType=VARCHAR}, ",
        "#{roleType,jdbcType=SMALLINT}, #{roleName,jdbcType=VARCHAR}, ",
        "#{roleRemark,jdbcType=VARCHAR}, #{delFlag,jdbcType=SMALLINT}, ",
        "#{createTime,jdbcType=TIMESTAMP}, #{createId,jdbcType=BIGINT}, ",
        "#{createAccount,jdbcType=VARCHAR}, #{optTime,jdbcType=TIMESTAMP}, ",
        "#{optId,jdbcType=BIGINT}, #{optAccount,jdbcType=VARCHAR})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="rowId", before=false, resultType=Long.class)
    int insert(SysRole record);

    @Select({
        "select",
        "ROW_ID, PARENT_ROLE_ID, PARENT_ROLE_NAME, ROLE_TYPE, ROLE_NAME, ROLE_REMARK, ",
        "DEL_FLAG, CREATE_TIME, CREATE_ID, CREATE_ACCOUNT, OPT_TIME, OPT_ID, OPT_ACCOUNT",
        "from sys_role",
        "where ROW_ID = #{rowId,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="ROW_ID", property="rowId", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="PARENT_ROLE_ID", property="parentRoleId", jdbcType=JdbcType.BIGINT),
        @Result(column="PARENT_ROLE_NAME", property="parentRoleName", jdbcType=JdbcType.VARCHAR),
        @Result(column="ROLE_TYPE", property="roleType", jdbcType=JdbcType.SMALLINT),
        @Result(column="ROLE_NAME", property="roleName", jdbcType=JdbcType.VARCHAR),
        @Result(column="ROLE_REMARK", property="roleRemark", jdbcType=JdbcType.VARCHAR),
        @Result(column="DEL_FLAG", property="delFlag", jdbcType=JdbcType.SMALLINT),
        @Result(column="CREATE_TIME", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="CREATE_ID", property="createId", jdbcType=JdbcType.BIGINT),
        @Result(column="CREATE_ACCOUNT", property="createAccount", jdbcType=JdbcType.VARCHAR),
        @Result(column="OPT_TIME", property="optTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="OPT_ID", property="optId", jdbcType=JdbcType.BIGINT),
        @Result(column="OPT_ACCOUNT", property="optAccount", jdbcType=JdbcType.VARCHAR)
    })
    SysRole selectByPrimaryKey(Long rowId);

    @Select({
        "select",
        "ROW_ID, PARENT_ROLE_ID, PARENT_ROLE_NAME, ROLE_TYPE, ROLE_NAME, ROLE_REMARK, ",
        "DEL_FLAG, CREATE_TIME, CREATE_ID, CREATE_ACCOUNT, OPT_TIME, OPT_ID, OPT_ACCOUNT",
        "from sys_role"
    })
    @Results({
        @Result(column="ROW_ID", property="rowId", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="PARENT_ROLE_ID", property="parentRoleId", jdbcType=JdbcType.BIGINT),
        @Result(column="PARENT_ROLE_NAME", property="parentRoleName", jdbcType=JdbcType.VARCHAR),
        @Result(column="ROLE_TYPE", property="roleType", jdbcType=JdbcType.SMALLINT),
        @Result(column="ROLE_NAME", property="roleName", jdbcType=JdbcType.VARCHAR),
        @Result(column="ROLE_REMARK", property="roleRemark", jdbcType=JdbcType.VARCHAR),
        @Result(column="DEL_FLAG", property="delFlag", jdbcType=JdbcType.SMALLINT),
        @Result(column="CREATE_TIME", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="CREATE_ID", property="createId", jdbcType=JdbcType.BIGINT),
        @Result(column="CREATE_ACCOUNT", property="createAccount", jdbcType=JdbcType.VARCHAR),
        @Result(column="OPT_TIME", property="optTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="OPT_ID", property="optId", jdbcType=JdbcType.BIGINT),
        @Result(column="OPT_ACCOUNT", property="optAccount", jdbcType=JdbcType.VARCHAR)
    })
    List<SysRole> selectAll();

    @Update({
        "update sys_role",
        "set PARENT_ROLE_ID = #{parentRoleId,jdbcType=BIGINT},",
          "PARENT_ROLE_NAME = #{parentRoleName,jdbcType=VARCHAR},",
          "ROLE_TYPE = #{roleType,jdbcType=SMALLINT},",
          "ROLE_NAME = #{roleName,jdbcType=VARCHAR},",
          "ROLE_REMARK = #{roleRemark,jdbcType=VARCHAR},",
          "DEL_FLAG = #{delFlag,jdbcType=SMALLINT},",
          "CREATE_TIME = #{createTime,jdbcType=TIMESTAMP},",
          "CREATE_ID = #{createId,jdbcType=BIGINT},",
          "CREATE_ACCOUNT = #{createAccount,jdbcType=VARCHAR},",
          "OPT_TIME = #{optTime,jdbcType=TIMESTAMP},",
          "OPT_ID = #{optId,jdbcType=BIGINT},",
          "OPT_ACCOUNT = #{optAccount,jdbcType=VARCHAR}",
        "where ROW_ID = #{rowId,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(SysRole record);
}